package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.bean.BillsTO;
import com.ecable.bean.ComplaintsTO;
import com.ecable.daoImpl.ConnectionDaoImpl;
import com.ecable.util.UtilConstants;

public class UserCompalintsAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8739119206017332679L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
	
		RequestDispatcher rd=null;

		boolean flag=false;
		String path="";
		ComplaintsTO cmp=new ComplaintsTO();
		cmp.setUserid(Integer.parseInt(request.getParameter("userid")));
		cmp.setCmpdiscription(request.getParameter("ComplaintDesc"));
		
		/*Map map=request.getParameterMap();
	 try {
		BeanUtils.populate(pack, map);
	} catch (IllegalAccessException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	} catch (InvocationTargetException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
		
	}*/
			try{
				flag=new ConnectionDaoImpl().addComplaint(cmp);
					
				if(flag){
					
					request.setAttribute("status", UtilConstants._ADD_COMPLAINT);
				
					path=UtilConstants._Coustomer_Home;
					
					
				}
				else{
					
					request.setAttribute("status", UtilConstants._cmp_ADD_FAILED);
					
					path=UtilConstants._Coustomer_Home;
					
				}
				
				
		}
			catch (Exception e) {
				e.printStackTrace();
				
				request.setAttribute("status", UtilConstants._cmp_ADD_FAILED);
				
				path=UtilConstants._Coustomer_Home;
				
			}
			
			
			 rd=request.getRequestDispatcher(path);
			
			rd.forward(request, response);
			
	}

}
